package spindles.api.services;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

import spindles.api.domain.Epoch;
import spindles.api.util.ApplicationException;
import spindles.api.util.UserException;

public abstract class DataExport {
	
	private NumberFormat format;

	public DataExport() {
		format = NumberFormat.getInstance(Locale.ENGLISH);
		((DecimalFormat)format).applyLocalizedPattern("##.##");
	}
	
	public void writeData(double[] data, File file){
		try {
			PrintWriter out = new PrintWriter(file);
			for(Double d : data){
				out.println(format.format(d));
			}			
			out.close();
			
		} catch (FileNotFoundException e) {
			throw new ApplicationException(e);
		}
	}
	
	public abstract double[] getData(Epoch e) throws UserException;
	
	

}
